<template>
  <div class="userInfo" v-if="profile">
    <!-- 头部导航 -->
    <div class="header">
      <div class="left iconfont icon-shouye" @click="$router.push('/')"></div>
      <div class="center">个人中心</div>
      <div
        class="right iconfont icon-search"
        @click="$router.push('/search')"
      ></div>
    </div>
    <div class="card">
      <div class="photo">
        <img :src="profile.avatarUrl" />
        <div class="vip">
          <span class="nickname">{{ profile.nickname }}</span>
          <span class="iconfont icon-VIP"></span>
        </div>
        <div class="follows">
          <span @click="$router.push('/userInfo/follows')"
            >{{ profile.follows }}&nbsp;关注</span
          >
          <span>{{ profile.followeds }}&nbsp;粉丝</span>
          <span class="level">Lv.{{ level }}</span>
        </div>
      </div>
      <div class="fontIcon">
        <van-grid :column-num="3">
          <van-grid-item
            text="最近播放"
            @click="$router.push('/userInfo/HistoryPlay')"
            ><template #icon>
              <div class="iconfont icon-bofang1"></div>
            </template>
          </van-grid-item>
          <van-grid-item
            text="我的好友"
            @click="$router.push('/userInfo/follows')"
          >
            <template #icon>
              <div class="iconfont icon-wodehaoyou"></div>
            </template>
          </van-grid-item>
          <van-grid-item text="我的播客">
            <template #icon>
              <div class="iconfont icon-shengbo"></div>
            </template>
          </van-grid-item>
          <van-grid-item
            text="云盘"
            @click="$router.push('/userInfo/cloudDisk')"
          >
            <template #icon>
              <div class="iconfont icon-yunshangchuan"></div>
            </template>
          </van-grid-item>
          <van-grid-item
            text="收藏"
            @click="$router.push(`/userInfo/collection/2363059491`)"
          >
            <template #icon>
              <div class="iconfont icon-shoucang1"></div>
            </template>
          </van-grid-item>
          <van-grid-item
            text="已购"
            @click="$router.push('/userInfo/purchased')"
          >
            <template #icon>
              <div class="iconfont icon-yigoushuliang"></div>
            </template>
          </van-grid-item>
        </van-grid>
      </div>
      <div class="songs">
        <div
          class="song"
          v-for="item in songs"
          :key="item.id"
          @click="$router.push(`/userInfo/collection/${item.id}`)"
        >
          <img :src="item.coverImgUrl" />
          <div class="title">
            <h3>{{ item.name }}</h3>
            <p>{{ item.trackCount }} 首</p>
          </div>
        </div>
      </div>
      <button class="logout" @click="getLogout">退出登录</button>
    </div>
  </div>
</template>

<script>
import {
  getUserDetail,
  getLogout,
  getUserPlaylist,
  getSongPurchased,
} from "@/api/userInfo";
export default {
  data() {
    return {
      uid: localStorage.getItem("uid"),
      profile: null,
      level: null,
      songs: [],
    };
  },
  created() {
    this.getUserDetail();
    this.getUserPlaylist();
  },
  methods: {
    async getUserCloud() {
      const { data } = await getSongPurchased();
      console.log(data);
      this.playList = data;
    },
    async getUserDetail() {
      const data = await getUserDetail({ uid: this.uid });
      console.log(data);
      this.profile = data.profile;
      this.level = data.level;
    },
    //退出登录
    getLogout() {
      getLogout();
      localStorage.clear();
      this.$router.push("/login");
    },
    async getUserPlaylist() {
      const { playlist } = await getUserPlaylist({ uid: this.uid });
      console.log("歌单", playlist);
      this.songs = playlist;
    },
  },
};
</script>

<style lang="less" scoped>
.userInfo {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100vh;
  z-index: 9;
  background: url("../assets/bg.webp") no-repeat;
  background-size: 100%;

  .header {
    color: #000;
    height: 5.5vh;
    line-height: 5.5vh;
    display: flex;
    font-weight: 600;
    text-align: center;
    .left,
    .right {
      flex: 0 0 40px;
      font-size: 18px;
    }
    .center {
      flex: 1;
    }
  }
  // 隐藏滚动条
  .card::-webkit-scrollbar {
    width: 0 !important;
  }
  .card {
    position: relative;
    margin: 0 10px;
    overflow-x: hidden;
    height: 94.5vh;
    .photo {
      position: relative;
      margin-top: 48px;
      height: 100px;
      width: 100%;
      border-radius: 10px;
      img {
        position: absolute;
        top: 0;
        left: 50%;
        transform: translate(-50%, -50%);
        border-radius: 50%;
        height: 65px;
        width: 65px;
      }
      .vip {
        position: relative;
        padding-top: 40px;
        text-align: center;
        .nickname {
          font-size: 18px;
          font-weight: bold;
        }
        .icon-VIP {
          position: absolute;
          line-height: 26px;
          height: 26px;
          font-size: 26px;
          color: #6d6262;
        }
      }
      .follows {
        display: flex;
        justify-content: center;
        span {
          margin: 0 10px;
          font-size: 13px;
          color: #191515;
        }
        .level {
          margin-top: 1px;
        }
      }
    }
    .fontIcon {
      background-color: #8b82932b;
      margin-top: 15px;
      border-radius: 10px;
      overflow: hidden;
      /deep/ [class*="van-hairline"]::after {
        border: 0;
      }
      .iconfont {
        font-size: 26px;
        color: #191515;
      }
      /deep/ .van-grid-item__text {
        color: #191515;
      }
    }

    .songs {
      background-color: #8b82932b;
      padding: 15px;
      margin-top: 20px;
      border-radius: 10px;
      .song {
        display: flex;
        align-items: flex-start;
        img {
          width: 45px;
          height: 45px;
          border-radius: 10px;
          margin-right: 10px;
          margin-bottom: 10px;
        }
        .title {
          h3 {
            color: #191515;
            font-size: 15px;
          }
          p {
            color: #191515;
            font-size: 14px;
          }
        }
      }
    }
    .logout {
      position: absolute;
      left: 0;
      right: 0;
      margin: 10px auto 0;
      width: 100%;
      height: 40px;
      border-radius: 10px;
      border: 0;
      background-color: #f02112;
      color: #fefefe;
    }
  }
}
</style>
